package com.admin.education.dataTransferObject.applyCrowds.Mapper;

import com.admin.education.dataTransferObject.applyCrowds.ApplyCrowdsTransfer;
import com.admin.education.dataTransferObject.role.mapper.RoleMapper;
import com.admin.education.models.ApplyCrowd;
import org.mapstruct.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public abstract class ApplyCrowdsMapper {
    @Autowired
    private RoleMapper roleMapper;
    @Mappings({
            @Mapping(target="role",ignore = true)
    })
    public abstract ApplyCrowdsTransfer mapFrom(ApplyCrowd applyCrowd);
    @Mappings({
    })
    public  abstract List<ApplyCrowdsTransfer> mapFrom(List<ApplyCrowd> applyCrowds);
    @AfterMapping
    public void afterMapping(ApplyCrowd applyCrowd, @MappingTarget ApplyCrowdsTransfer applyCrowdsTransfer){
        if(null!=applyCrowd.getRole()){
            applyCrowdsTransfer.setRole(roleMapper.mapFrom(applyCrowd.getRole()));
        }
    }
}
